﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using AspNetCs.Model;
using AspNetCs.Common;
using AspNetCs.Enumerations.TrueOrFalseEnum;
using AspNetCs.Bll;
using AspNetCs.Enumerations.User_Enum;

public partial class UserAddLink : BasePage
{

    protected string Action = "";
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Request["Action"] != null)
        {
            Action = Request["Action"];

        }
        if (configInfo.IsLinkUrl == (int)IsTrueEnum.NO)
        {
            Response.Write("对不起，暂时不允许申请友情链接!");
            Response.End();
        }


        if (!Page.IsPostBack)
        {
            switch (Action)
            {
                case "txt":
                    RadioButtonList1.Items.Clear();
                    ListItem itm = new ListItem("文字链接", "2");
                    itm.Selected = true;
                    RadioButtonList1.Items.Add(itm);
                    Page.RegisterStartupScript("OnLoadlogo", "<script>document.getElementById(\"LogoRow\").style.display='none';</script>");
                    this.RequiredFieldValidator6.Visible = false;
                    break;
                case "pic":
                    RadioButtonList1.Items.Clear();
                    ListItem itmpic = new ListItem("Logo链接", "1");
                    itmpic.Selected = true;
                    RadioButtonList1.Items.Add(itmpic);
                    break;
            }
        }

    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        if (configInfo.IsLinkUrl == (int)IsTrueEnum.Yes)
        {
            FriendSite_Model model = new FriendSite_Model();
            model.SiteName = StringHelper.HtmlEncrypt(Txt_webName.Text);
            model.LinkType = StringHelper.isNumber_int(RadioButtonList1.SelectedValue);
            model.SiteUrl = StringHelper.HtmlEncrypt(Txt_Url.Text);
            model.SiteIntro = StringHelper.HtmlEncrypt(Txt_Readme.Text);
            model.LogoUrl = StringHelper.HtmlEncrypt(Txt_Logo.Text);
            model.SiteAdmin = "";
            model.Email = StringHelper.HtmlEncrypt(Txt_Email.Text);
            model.SitePwd = "";
            model.IsGood = (int)IsTrueEnum.NO;
            model.IsCheck = (int)IsTrueEnum.NO;

            int Result = FriendSite_Bll.CreateNew.Add(model);
            if (Result > 0)
            {
                string T = "";
                if (model.LinkType == (int)LinkTypeEnum.text) { T = "txt"; } else { T = "pic"; }
                Response.Write("<script>alert('友情链接申请添加成功');location.href='UserAddLink.Aspx?Action=" + T + "';</script>");
            }
            else
            {
                Response.Write("<script>alert('友情链接申请添加失败');history.back();</script>");
            }
        }

        Response.End();


    }
}
